<?php

namespace service\uc\oauth;

use config\Config;
use Log;
class NativeMobileAuthClient extends BaseAuthClient
{

    function code2verifyinfo($code)
    {
        $url = "https://api.weixin.qq.com/donut/code2verifyinfo";
        $params = [
            'appid' => Config::DONUT['appId'],
            'appsecret' => Config::DONUT['secret'],
            'code' => $code,
            'grant_type' => 'authorization_code',
        ];

        $res = $this->getRequest($url, $params);

        Log::debug('code2verifyinfo', $res);

        $json = json_decode($res);

        if($json && isset($json->user_info->phone_info->phone)){
            return $json->user_info->phone_info->phone;
        }else{
            Log::error("code2verifyinfo code=$code", $res);
            return null;
        }
    }

}